<template>
  <!-- hidden PageHeaderWrapper title demo -->
  <page-header-wrapper :title="false" >
    <a-card :body-style="{padding: '24px 32px'}" :bordered="false">
      <a-form @submit="handleSubmit" :form="form">
        <a-form-item
          label="积分规则："
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  
        </a-form-item>
        <a-form-item
          label=""
          v-show="false"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'id',
            ]"
            name="id"/>
        </a-form-item>
        <a-form-item
          label="每消费"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'spentAmount',
              {rules: [{ required: true, message: '请输入每消费' }]}
            ]"
            addonAfter="元"
            name="spentAmount"
            placeholder="请输入每消费" />
        </a-form-item>
        <a-form-item
          label="可累积"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'harvestIntegral',
              {rules: [{ required: true, message: '请输入可累积' }]}
            ]"
            addonAfter="分"
            name="harvestIntegral"
            placeholder="请输入可累积" />
         
        </a-form-item>
        <a-form-item
          label="单次积分上限"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'tenantId',
              {rules: [{ required: true, message: '请输入单次积分上限' }]}
            ]"
            addonAfter="分 零为不限"
            name="tenantId"
            placeholder="请输入单次积分上限" />
          
        </a-form-item>
        <a-form-item
          label="抵扣规则："
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
  
        </a-form-item>
        <a-form-item
          label="每使用"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'deductionIntegral',
              {rules: [{ required: true, message: '请输入每使用' }]}
            ]"
            addonAfter="分"
            name="deductionIntegral"
            placeholder="请输入每使用" />
          
        </a-form-item>
        <a-form-item
          label="可抵扣"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'deductionAmount',
              {rules: [{ required: true, message: '请输入可抵扣' }]}
            ]"
            addonAfter="元"
            name="deductionAmount"
            placeholder="请输入可抵扣" />
          
        </a-form-item>
        <a-form-item
          label="单次使用上限"
          :labelCol="{lg: {span: 7}, sm: {span: 7}}"
          :wrapperCol="{lg: {span: 10}, sm: {span: 17} }">
          <a-input
            v-decorator="[
              'singleMaxDeduction',
              {rules: [{ required: true, message: '请输入单次使用上限' }]}
            ]"
            addonAfter="分 零为不限"
            name="singleMaxDeduction"
            placeholder="请输入单次使用上限" />
          
        </a-form-item>
        <a-form-item
          :wrapperCol="{ span: 24 }"
          style="text-align: center"
        >
          <a-button htmlType="submit" :loading="loading" type="primary">提交</a-button>
          <!-- <a-button style="margin-left: 8px">{{ $t('form.basic-form.form.save') }}</a-button> -->
        </a-form-item>
      </a-form>
    </a-card>
  </page-header-wrapper>
</template>
  
<script>
import { getIntegralSettingUsingPOST,updateIntegralSettingUsingPOST } from '@/api/api/xitongguanli.ts'
import pick from 'lodash.pick'
  const fields = ['deductionAmount','deductionIntegral','harvestIntegral', 'singleMaxDeduction', 'singleMaxDeduction','spentAmount','tenantId','id']
  export default {
    name: 'Score',
    data () {
      return {
        form: this.$form.createForm(this),
        loading: false
      }
    },
    mounted(){
      this.getDetail()
    },
    methods: {
      getDetail(){
        getIntegralSettingUsingPOST(this.queryParam).then((res) => {
          this.form.setFieldsValue(pick(res.data, fields))
        })
        .catch((error) => {
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
      },
      // handler
      handleSubmit (e) {
        this.loading = true
        e.preventDefault()
        this.form.validateFields((err, values) => {
          if (!err) {
            // console.log(values)
            updateIntegralSettingUsingPOST({...values}).then((res) => {
              this.$message.success('操作成功')
              this.loading = false
              this.getDetail()
            })
            .catch(() => {
              this.$message.error('设置失败,请联系管理员!')
            })
          }
        })
      }
    }
  }
</script>